package com.beinfo.contract.service;

import java.sql.SQLException;

import com.beinfo.contract.dao.UserDao;
import com.beinfo.contract.model.User;
public class UserService {
	UserDao userDao = new UserDao();
			
	public User login(String username, String password) throws Exception {
		
		User user=null;
		try {
			user = userDao.findUserByUserNameAndPassword(username,password);
			if(user==null){
				throw new Exception("用户名或密码错误!");
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
			throw new Exception("用户名或密码错误!");
		}
		return user;
	}

	public void regist(User user) throws Exception {
		try {
			userDao.addUser(user);//用户注册
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("注册失败！");
		}
	}

}
